local skynet = require "skynet"
local ServiceName = require "enum.ServiceName"

local LOG_TYPE = {
    LOG = "LOG",
    WARN = "WARN",
    ERROR = "ERROR"
}

local function log(channel, log_type, ...)
    skynet.send(ServiceName.GAME_LOGGER, "lua", log_type, channel, ...)
end

function LLOG(channel, ...)
    log(channel, LOG_TYPE.LOG, ...)
end

function LWARN(channel, ...)
    log(channel, LOG_TYPE.WARN, ...)
end

function LERR(channel, ...)
    log(channel, LOG_TYPE.ERROR, ...)
end

-- 格式化字符串打印日志
function LLOGF(channel, ...)
    log(channel, LOG_TYPE.LOG, string.format(...))
end

function LWARNF(channel, ...)
    log(channel, LOG_TYPE.WARN, string.format(...))
end

function LERRF(channel, ...)
    log(channel, LOG_TYPE.ERROR, string.format(...))
end

-- 游戏运行日志
local game_channel = "GAME"
function GLOG(...)
    log(game_channel, LOG_TYPE.LOG, ...)
end

function GWARN(...)
    log(game_channel, LOG_TYPE.WARN, ...)
end

function GERR(...)
    log(game_channel, LOG_TYPE.ERROR, ...)
end

-- 格式化字符串打印日志
function GLOGF(...)
    log(game_channel, LOG_TYPE.LOG, string.format(...))
end

function GWARNF(...)
    log(game_channel, LOG_TYPE.WARN, string.format(...))
end

function GERRF(...)
    log(game_channel, LOG_TYPE.ERROR, string.format(...))
end

local oldAssert = assert
function assert(condition, message)
    if not condition then
        GERR(message)
    end

    return oldAssert(condition, message)
end